import React, { useState } from 'react';
import { Modal, Radio, Row, Col, Checkbox, Button } from 'antd';

function CloseApp(props) {
  // const [visible, setVisible] = useState(false);
  const { visible, path, setVisible } = props;

  const [noPrompt, setNoPrompt] = useState<boolean>(false);
  const [closeType, setCloseType] = useState<number>(1);

  return (
    <div>
      <Modal
        title="关闭提示"
        visible={visible}
        footer={false}
        onCancel={() => {
          setVisible(false);
        }}
      >
        <div>
          <Radio.Group
            value={closeType}
            onChange={(e) => setCloseType(e.target.value)}
            style={{ width: '100%' }}
          >
            <Row justify="center">
              <Col span={12} style={{ marginBottom: 10 }}>
                <Radio value={1}>最小化到系统托盘</Radio>
              </Col>
            </Row>
            <Row justify="center">
              <Col span={12} style={{ marginBottom: 15 }}>
                <Radio value={2}>退出工程数字化平台</Radio>
              </Col>
            </Row>
          </Radio.Group>

          <Row justify="space-between" align="middle">
            <Checkbox
              value={noPrompt}
              onChange={(e) => {
                setNoPrompt(e.target.checked);
              }}
            >
              不再提醒
            </Checkbox>
            <Button
              type="primary"
              onClick={() => {
                setVisible(false);
                if(noPrompt){
                  window.electron.store.set('noPrompt', closeType);
                }else{
                  window.electron.store.set('noPrompt', null);
                }
                if (closeType == 1) {
                  window.electron.ipcRenderer.sendMessage(
                    'index:opertion',
                    'hide'
                  );
                } else {
                  window.electron.ipcRenderer.sendMessage(
                    'index:opertion',
                    'quit'
                  );
                }
              }}
            >
              确认
            </Button>
          </Row>
        </div>
      </Modal>
    </div>
  );
}

export default CloseApp;
